//
//  MyView.m
//  悦读
//
//  Created by dllo on 15/6/8.
//  Copyright (c) 2015年 华东伟. All rights reserved.
//

#import "MyView.h"

@implementation MyView

- (void)dealloc
{
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
//        self.page = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, 200, 40)];
        self.page.center = self.center;
        self.page = [[UIPageControl alloc]initWithFrame:CGRectMake(self.page.center.x + 70, self.page.center.y + 150, 200, 40)];
        [self.page setBackgroundColor:[UIColor clearColor]];
        [self setBackgroundColor:[UIColor whiteColor]];
        self.page.currentPage = 0;
        self.page.numberOfPages = 6;
        // 当前page指示的颜色
        self.page.currentPageIndicatorTintColor = [UIColor greenColor];
        [self addSubview:self.page];
        
        [self.page release];
        
        if (self.timer) {
            [self.timer invalidate];
            self.timer = nil;
        }
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    }
    return self;
}

- (void)timerAction:(NSTimer *)timer
{
    
    
    
    [UIView animateWithDuration:5 animations:^{
          if (self.page.currentPage == 5) {
            self.page.currentPage = 0;
            
        }
          else
        {
            
            self.page.currentPage ++;
        }
        self.page.currentPageIndicatorTintColor = [UIColor greenColor];
        
    }];
    
    
}


+ (MyView *)createPageView
{
    MyView *view = [[MyView alloc]initWithFrame:CGRectMake(0, 30, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 64 - 49)];
    
    [view release];
    
    return view;
    
}


@end
